/**
 * 
 */
package com.ms.game.lobby.command;

import org.hibernate.Session;

import com.ms.game.db.util.UpdateQueryBuilder;
import com.ms.service.module.zone.command.BasicDebugCommand;
import com.xpec.c4.db.hibernate.manager.HibernateManager;
import com.xpec.c4.game.utility.GUID;
import com.xpec.c4.service.contexts.Contexts;

/**
 * 連續登陸獎勵測試指令<br>
 * 設定角色可領的連續登陸獎勵數量<br>
 * 暫時只針對首儲獎勵部分設定(因為帳號認證部分還未實做)<br>
 * <p>
 * 參數1 連續登陸天數 <br>
 * 參數2 首儲獎勵已領數量 <br>
 * 可領數量 = 連續登陸天數 - 首儲獎勵已領數量  (上限為5)
 * 
 * @author yulo
 */
public class ContinueRewardCommand extends BasicDebugCommand {


	public ContinueRewardCommand() {
		
	}
	
	@Override
	public String execute() {
		if(commandValue.length < 3){
			return "command parameter error!";
		}

		int continuousLoginCount = Integer.valueOf(commandValue[1]);
		int firstStoreReward = Integer.valueOf(commandValue[2]);
		
		int check = continuousLoginCount - firstStoreReward;
		if(check < 0 || firstStoreReward >= 5){
			return "command parameter error!";
		}
		
		GUID id = Contexts.getUserID();
		Session session = HibernateManager.txBegin();
		UpdateQueryBuilder bb = new UpdateQueryBuilder();
		bb.setSession(session);
		bb.setTableName("PlayerModel");
		bb.addSetValue("storeRewardContinuousLoginCount", continuousLoginCount );
		bb.addSetValue("firstStoreReward", firstStoreReward );
		bb.setWhereKey("guid", id.toString());
		bb.executeQuery();
		HibernateManager.txCommitFailRollbackClearSession();

		return "ok";
	}

	@Override
	public String getName() {
		return "crd";
	}

	@Override
	public String getDescription() {
		return "";
	}

	@Override
	public String getShortDescription() {
		return "nothing ....";
	}
}
